import javax.swing.plaf.IconUIResource;

class solution{
      //第一个单独的字母
    public int first(String str){
        int count[] = new int[26];
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            count[ch - 'a']++;
        }

        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            if (count[ch - 'a'] == 1) {
                return i;
            }
        }
        return -1;
    }



    //字符串最后一个单词的长度
    /*1.
    public int lastLength(String s){
        int count=0;
        for (int i = s.length()-1; i >0 ; i--) {
            if(s.charAt(i)==' '){
                break;
            }
            count++;
        }
        return count;
    }*/

    //2.
    public int lastLength(String s){
        String[] words = s.split(" ");
        return words[words.length-1].length();
    }


    public boolean isLeagal(char ch){
        if (ch >= 'a' && ch <= 'z' || ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z'){
            return true;
        }
        return false;
    }

    public boolean isPalindrome(String s){
        s=s.toLowerCase();
        int left = 0;
        int right = s.length()-1;
        while(left<right && isLeagal(s.charAt(left)) && isLeagal(s.charAt(right))){
            if(s.charAt(left) != s.charAt(right)){
                return false;
            }
            left++;
            right--;
        }
        return left>=right;
    }
}
public class work {
    public static void main(String[] args) {
        String s="adba";
        solution solution = new solution();
        System.out.println(solution.first(s));

        String str ="hello world";
        System.out.println(solution.lastLength(str));

        String str2 = "A man, a plan, a canal: Panama";
       Boolean ret = solution.isPalindrome(str2);
        System.out.println(ret);
    }

}
